﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    public class CNVP_CreditInflux
    {
        private string Prefix = DBConfig.Prefix;
        public int Insert(Model.CNVP_CreditInflux obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into  " + Prefix + "CreditInflux ([OperatorID],[OperatTime],[OperaType],[OperaTargID],[QriginalCredit],[PresentCredit],[Remark])");
            sql.Append("values(@OperatorID,@OperatTime,@OperaType,@OperaTargID,@QriginalCredit,@PresentCredit,@Remark)");

            SqlParameter[] pra = {
                            new SqlParameter("@OperatorID",obj.OperatorID),
                            new SqlParameter("@OperatTime",obj.OperatTime),
                            new SqlParameter("@OperaType",obj.OperaType),
                            new SqlParameter("@OperaTargID",obj.OperaTargID),
                            new SqlParameter("@QriginalCredit",obj.QriginalCredit),
                            new SqlParameter("@PresentCredit",obj.PresentCredit),
                            new SqlParameter("@Remark",obj.Remark)
                                 };
            return DbHelper.ExecuteNonQuery(sql.ToString(), pra);
        }

        public int Update(Model.CNVP_CreditInflux obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("update " + Prefix + "OperateLog set [OperatorID] = @OperatorID,OperatTime=@OperatTime ,[OperaType]=@OperaType,[OperaTargID]=@OperaTargID,[QriginalCredit]=@QriginalCredit,[PresentCredit]=@PresentCredit ,[Remark]=@Remark  where [ID] = @ID");

            SqlParameter[] pra = { 
                            new SqlParameter("@ID",obj.ID),
							new SqlParameter("@OperatorID",obj.OperatorID),
                            new SqlParameter("@OperatTime",obj.OperatTime),
                            new SqlParameter("@OperaType",obj.OperaType),
                            new SqlParameter("@OperaTargID",obj.OperaTargID),
                            new SqlParameter("@QriginalCredit",obj.QriginalCredit),
                            new SqlParameter("@PresentCredit",obj.PresentCredit),
                            new SqlParameter("@Remark",obj.Remark)
                                };
            return DbHelper.ExecuteNonQuery(sql.ToString(), pra);
        }

        public int Delete(Model.CNVP_CreditInflux obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("delete from " + Prefix + "OperateLog where [ID] = @ID");
            SqlParameter[] pra = {
                                new SqlParameter("@ID",obj.ID)
						
                                };
            return DbHelper.ExecuteNonQuery(sql.ToString(), pra);
        }


        public Model.CNVP_CreditInflux LoadById(int ID)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [OperatorID],[OperatTime],[OperaType],[OperaTargID],[QriginalCredit],[PresentCredit],[Remark] from " + Prefix + "OperateLog");
            sql.Append(" where [ID] = @ID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ID",ID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(), pra);
            Model.CNVP_CreditInflux CNVP_CreditInflux = new Model.CNVP_CreditInflux();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                CNVP_CreditInflux.OperatorID = dr["OperatorID"] is DBNull ? 0 : (int)dr["OperatorID"];
                CNVP_CreditInflux.OperatTime = dr["OperatTime"] is DBNull ? String.Empty : (string)dr["OperatTime"];
                CNVP_CreditInflux.OperaType = dr["OperaType"] is DBNull ? 0 : (int)dr["OperaType"];
                CNVP_CreditInflux.OperaTargID = dr["OperaTargID"] is DBNull ? String.Empty : (string)dr["OperaTargID"];
                CNVP_CreditInflux.QriginalCredit = dr["QriginalCredit"] is DBNull ? String.Empty : (string)dr["QriginalCredit"];
                CNVP_CreditInflux.PresentCredit = dr["PresentCredit"] is DBNull ? String.Empty : (string)dr["PresentCredit"];
                CNVP_CreditInflux.Remark = dr["Remark"] is DBNull ? String.Empty : (string)dr["Remark"];
            }
            return CNVP_CreditInflux;
        }


        public List<Model.CNVP_CreditInflux> LoadAll(string SqlWhere)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[OperatorID],[OperatTime],[OperaType],[OperaTargID],[QriginalCredit],[PresentCredit],[Remark] from " + Prefix + "OperateLog");
            if (SqlWhere.Trim() != "")
            {
                sql.Append(" where " + SqlWhere);
            }
            DataTable DT = DbHelper.ExecuteTable(sql.ToString());
            List<Model.CNVP_CreditInflux> list = new List<Model.CNVP_CreditInflux>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_CreditInflux CNVP_CreditInflux = new Model.CNVP_CreditInflux();
                    CNVP_CreditInflux.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    CNVP_CreditInflux.OperatorID = dr["OperatorID"] is DBNull ? 0 : (int)dr["OperatorID"];
                    CNVP_CreditInflux.OperatTime = dr["OperatTime"] is DBNull ? String.Empty : (string)dr["OperatTime"];
                    CNVP_CreditInflux.OperaTargID = dr["OperaTargID"] is DBNull ? String.Empty : (string)dr["OperaTargID"];
                    CNVP_CreditInflux.QriginalCredit = dr["QriginalCredit"] is DBNull ? String.Empty : (string)dr["QriginalCredit"];
                    CNVP_CreditInflux.PresentCredit = dr["PresentCredit"] is DBNull ? String.Empty : (string)dr["PresentCredit"];
                    CNVP_CreditInflux.Remark = dr["Remark"] is DBNull ? String.Empty : (string)dr["Remark"];
                    list.Add(CNVP_CreditInflux);
                }
            }
            return list;
        }
    }
}
